package com.zhkc.wisdom.common.base.exception;

import cn.hutool.http.HttpStatus;
import com.zhkc.wisdom.common.base.enums.ErrorCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
@AllArgsConstructor
public class BusinessException extends RuntimeException {

    private Integer errorCode;
    private String errorMsg;

    public static BusinessException thrown(ErrorCodeEnum errorCodeEnum) {
        BusinessException exception = new BusinessException();
        exception.setErrorCode(errorCodeEnum.getErrorCode());
        exception.setErrorMsg(errorCodeEnum.getMsg());
        return exception;
    }

    public BusinessException(String msg) {
        this.errorMsg = msg;
    }

    public BusinessException(String msg,Integer code) {
        this.errorMsg = msg;
        this.errorCode = code;
    }

}
